package cn.bdqn.mallmgr.service.impl;

import cn.bdqn.mallmgr.dao.CategoryMapper;
import cn.bdqn.mallmgr.dao.ProductMapper;
import cn.bdqn.mallmgr.pojo.Category;
import cn.bdqn.mallmgr.service.CategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author
 * @create 2022-07-12 18:18
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Resource
    private CategoryMapper categoryMapper;
    @Resource
    private ProductMapper productMapper;

    /**
     * 获取商品分类及分类下的前8个商品
     *
     * @return java.util.List<cn.bdqn.mallmgr.pojo.Category>
     */
    @Override
    public List<Category> getAllCategories() {
        List<Category> categories = categoryMapper.getAllCategories();
        for (int i = 0; i < categories.size(); i++) {
            Category category = categories.get(i);
            category.setProducts(productMapper.getProductsByCategory(category.getCategoryId()));
        }
        return categories;
    }
}
